﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace FileManager
{
    public class FileManager
    {
        private static FileConfig fg =  new FileConfig();
        private static Record record = new Record();
        private static Alarm alarm = new Alarm();
        private static Snap snap = new Snap();
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="confFilePath"></param>
        public FileManager()
        {
            
        }
        /// <summary>
        /// 初始化，读所有的配置文件
        /// </summary>
        public static void Initialize()
        {
            fg.ReadAllConf();
        }
       
        /// <summary>
        /// 得到该设备将于录像时自动根据当然的时间日期生成相应的文件路径和文件名
        /// </summary>
        /// <param name="DeviceArea">区域名</param>
        /// <param name="DeviceName">设备名</param>
        /// <returns></returns>
        public static string GetRecordingFileName(string DeviceArea, string DeviceName)
        {
            return record.GetRecordingFileName(fg.GetRecordRoot(DeviceArea, DeviceName));
        }

        /// <summary>
        ///  根据区域名和设备名,年和月获取该年该月下有多少天的录像文件
        /// </summary>
        /// <param name="DeviceArea">区域名</param>
        /// <param name="DeviceName">设备名</param>
        /// <param name="year">年份</param>
        /// <param name="month">月份</param>
        /// <returns>该年该月下的每天录像的的文件列表</returns>
        public static DirectoryInfo[] GetRecordDay(string DeviceArea, string DeviceName, string year, string month)
        {
            int m = Convert.ToInt32(month);
            string path = fg.GetRecordRoot(DeviceArea, DeviceName) + string.Format("{0}\\{1:D2}\\", year, m);
            return record.GetRecordDay(path);
        }

        /// <summary>
        /// 根据区域名和设备名,根据年月日获取当前日期下所有的录像文件
        /// </summary>
        /// <param name="DeviceArea">区域名</param>
        /// <param name="DeviceName">设备名</param>
        /// <param name="year">年</param>
        /// <param name="month">月</param>
        /// <param name="day">日</param>
        /// <returns>返回当前日期下所有的录像文件</returns>
        public static FileInfo[] GetRecordList(string DeviceArea, string DeviceName, string year, string month, string day)
        {
            int m = Convert.ToInt32(month);
            int d = Convert.ToInt32(day);
            string path = fg.GetRecordRoot(DeviceArea, DeviceName) + string.Format("{0}\\{1:D2}\\{2:D2}\\", year, m, d);
            return record.GetRecordList(path);
        }
        public static DirectoryInfo[] GetAlarmDay(string DeviceArea, string DeviceName, string year, string month)
        {
            int m = Convert.ToInt32(month);
            string path = fg.GetAlarmRoot(DeviceArea, DeviceName) + string.Format("{0}\\{1:D2}\\", year, m);
            return alarm.GetRecordDay(path);
        }
        public static string GetAlarmFileName(string DeviceArea, string DeviceName, bool isFirstFrame,short horizonAngle,short verticalAngle)
        {
            return alarm.GetAlarmFileName(fg.GetAlarmRoot(DeviceArea, DeviceName), isFirstFrame, horizonAngle, verticalAngle);
        }

        public static DirectoryInfo[] GetAlarmFileList(string DeviceArea, string DeviceName, string year, string month, string day)
        {
            int m = Convert.ToInt32(month);
            int d = Convert.ToInt32(day);
            string path = fg.GetAlarmRoot(DeviceArea, DeviceName) + string.Format("{0}\\{1:D2}\\{2:D2}\\", year, m, d);
            return alarm.GetAlarmList(path);
        }

        public static string GetSnapFileName(string DeviceArea, string DeviceName)
        {
            return snap.GetSnapFileName(fg.GetSnapRoot(DeviceArea, DeviceName));
        }
        /// <summary>
        /// 根据配置文件获取设备的列表
        /// </summary>
        /// <returns></returns>
        public static Dictionary<string, List<string>> GetDeviceList()
        {
            return fg.GetDeviceList();
        }

        /// <summary>
        /// 根据区域名和设备名获得设备相关的信息
        /// </summary>
        /// <param name="DeviceArea">区域名</param>
        /// <param name="DeviceName">设备名</param>
        /// <returns></returns>
        public static DeviceInfo GetDeviceInfo(string DeviceArea, string DeviceName)
        {
            return fg.GetDeviceInfo(DeviceArea,DeviceName);
        }
    }

}
